#define  _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>
void test1(int *a,int n)
{
	for (int i = 0; i < n - 1; i++)
	{
		int end = i;
		int temp = a[end + 1];
		while (end>=0)
		{
			if (a[end] > a[end + 1])
			{
				a[end + 1] = a[end];
				end--;
			}
			else
			{
				break;
			}
			a[end + 1] = temp;
		}
	}
}
void test2(int* a, int n)
{
	int gap = n;
		while (gap>1)
		{
			gap /= 2;
			for (int i = 0; i < n - gap; i++)
			{

			int end = i;
			int temp = a[end + gap];
			while (end >= 0)
			{
				if (a[end] > a[end + gap])
				{
					a[end + gap] = a[end];
					end -= gap;
				}
				else
					break;
			}
			a[end + gap] = temp;
		}
	}
	
}
int main()
{
	int a[] = { 2,4,1,5,3,8,6,9,7,10 };
	test2(a,sizeof(a)/sizeof(int));
	for (int i = 0; i < sizeof(a) / sizeof(int); i++)
	{
		printf("%d ", a[i]);
	}
	return 0;
}